#include "StringArray.h"

bool equalsIgnoreCase(std::string str1, std::string str2)
{
    size_t len = str1.length();
    if (len != str2.length()) {
        return false;
    }
    for (size_t i = 0; i < len; i++) {
        if (tolower(str1[i]) != tolower(str2[i])) {
            return false;
        }
    }
    return true;
}

bool FILE_IS_REAL(const char* path)
{
    struct stat path_stat;
    if (stat(path, &path_stat) == -1) {
        return false;
    }
    if (S_ISDIR(path_stat.st_mode)) {
        return false;
    }
    return true;
}

bool FILE_EXISTS(const char* path)
{
    struct stat path_stat;
    return stat(path, &path_stat) == -1 ? false : true;
}

#define WHITESPACE " \t\n\r\f\v"
void trim(std::string &str)
{
    size_t start = str.find_first_not_of(WHITESPACE);
    if (start == std::string::npos) {
        str.clear();
        return;
    }
    size_t end = str.find_last_not_of(WHITESPACE);
    str = str.substr(start, end - start + 1);
}